//会员登录状态(token)的store【与服务器端交互时，验证的令牌】

import { defineStore } from "pinia";
import { ref } from "vue";

export const useToken = defineStore(
  "token",
  () => {
    //定义状态数据(state)
    const token = ref(null);

    //修改token的方法(action)
    const updateToken = (val: any) => {
      token.value = val;
    };

    //移除token的方法(action)
    const removeToken = () => {
      token.value = null;
    };

    //以对象形式返回
    return { token, updateToken, removeToken };
  },
  {
    persist: {
      key: "token",
      storage: sessionStorage,
    },
  }
);
